<template>
    <span v-bind="$attrs" v-on="$listeners">{{fieldValue}}</span>
</template>

<script>
  import moment from 'moment'
  export default {
    props: {
      value: {
        type: [String,Number]
      }
    },
    computed: {
      fieldValue: {
        get() {
          if(this.value > 0) {
              var date = this.value || Date.now();
              var format = this.$attrs.format ? this.$attrs.format : 'YYYY-MM-DD hh:mm:ss';
             return moment(date * 1000).format(format);
          }else if((new Date(this.value)).getTime() > 0) {
             var date = (new Date(this.value)).getTime();
              var format = this.$attrs.format ? this.$attrs.format : 'YYYY-MM-DD hh:mm:ss';
             return moment(date).format(format);
          }else{
              return ' -- ';
          }
        },
        set(val) {
          this.$emit('input', val)
        }
      }
    }
  }
</script>
